﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Configuration;

namespace Sausage.Common
{
    public static class Utility
    {
        public static bool IsDebug
        {
            get
            {
#if DEBUG
                return true;
#else
                return false;
#endif
            }
        }


        /// <summary>
        /// 组织结构分类定义
        /// </summary>
        public static readonly Dictionary<int, string> OrganizationCategoryDictionary;

        public static readonly Dictionary<string, string> ContentTypeDictionary;

        static Utility()
        {
            OrganizationCategoryDictionary = new Dictionary<int, string>
                                                 {
                                                     {0, "总段"},
                                                     {1, "分段"},
                                                     {2, "养护分组"},
                                                     {3, "项目分组"}
                                                 };

            ContentTypeDictionary = new Dictionary<string, string>
                                        {
                                            //Images
                                            {".bmp", "image/bmp"},
                                            {".gif", "image/gif"},
                                            {".jpeg", "image/jpeg"},
                                            {".jpg", "image/jpeg"},
                                            {".png", "image/png"},
                                            {".tif", "image/tiff"},
                                            {".tiff", "image/tiff"},
                                            //Documents
                                            {".doc", "application/msword"},
                                            {".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"},
                                            {".pdf", "application/pdf"},
                                            //Slideshows
                                            {".ppt", "application/vnd.ms-powerpoint"},
                                            {".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"},
                                            //Data
                                            {".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
                                            {".xls", "application/vnd.ms-excel"},
                                            {".csv", "text/csv"},
                                            {".xml", "text/xml"},
                                            {".txt", "text/plain"},
                                            //Compressed Folders
                                            {".zip", "application/zip"},
                                            //Audio
                                            {".ogg", "application/ogg"},
                                            {".mp3", "audio/mpeg"},
                                            {".wma", "audio/x-ms-wma"},
                                            {".wav", "audio/x-wav"},
                                            //Video
                                            {".wmv", "audio/x-ms-wmv"},
                                            {".swf", "application/x-shockwave-flash"},
                                            {".avi", "video/avi"},
                                            {".mp4", "video/mp4"},
                                            {".mpeg", "video/mpeg"},
                                            {".mpg", "video/mpeg"},
                                            {".qt", "video/quicktime"}
                                        };
        }

        public static string GetCategoyNameByCode(int code)
        {
            return OrganizationCategoryDictionary[code];
        }

        private static readonly string projectFolder = WebConfigurationManager.AppSettings["ProjectFolder"];
        public static string ProjectFolder
        {
            get { return projectFolder; }
        }

        private static readonly string maintainJournalFolder = WebConfigurationManager.AppSettings["MaintainJournalFolder"];
        public static string MaintainJournalFolder
        {
            get { return maintainJournalFolder; }
        }

        private static readonly string projectJournalFolder = WebConfigurationManager.AppSettings["ProjectJournalFolder"];
        public static string ProjectJournalFolder
        {
            get { return projectJournalFolder; }
        }

        private static readonly string emergencyFolder = WebConfigurationManager.AppSettings["EmergencyFolder"];
        public static string EmergencyFolder
        {
            get { return emergencyFolder; }
        }

        private static readonly string tempFileFolder = WebConfigurationManager.AppSettings["TempFileFolder"];
        public static string TempFileFolder
        {
            get { return tempFileFolder; }
        }

        private static readonly string defaultPassword = WebConfigurationManager.AppSettings["DefaultPassword"];
        public static string DefaultPassword
        {
            get { return defaultPassword; }
        }

        private static readonly int instructionNewPeriod = int.Parse(WebConfigurationManager.AppSettings["InstructionNewPeriod"]);
        public static int InstructionNewPeriod
        {
            get { return instructionNewPeriod; }
        }

        private static readonly int couldDelayHours = int.Parse(WebConfigurationManager.AppSettings["CouldDelayHours"]);
        public static int CouldDelayHours
        {
            get { return couldDelayHours; }
        }

        public static string GetContentTypeFromFileExtension(string fileExtension)
        {
            if (ContentTypeDictionary.Keys.Contains(fileExtension))
                return ContentTypeDictionary[fileExtension];
            return string.Empty;
        }

        private static readonly bool isScalePhoto = bool.Parse(WebConfigurationManager.AppSettings["IsScalePhoto"]);
        public static bool IsScalePhoto
        {
            get { return isScalePhoto; }
        }

        private static readonly int scalePhotoWidth = int.Parse(WebConfigurationManager.AppSettings["ScalePhotoWidth"]);
        public static int ScalePhotoWidth
        {
            get { return scalePhotoWidth; }
        }

        private static readonly int scalePhotoHeight = int.Parse(WebConfigurationManager.AppSettings["ScalePhotoHeight"]);
        public static int ScalePhotoHeight
        {
            get { return scalePhotoHeight; }
        }
    }
}
